package com.wctj.api.base.dto;

import com.wctj.api.base.Result;
import org.springframework.http.HttpStatus;

import java.util.Objects;

public class ResponseResult<T> extends Result<T> {

    private static final String SUCCESS_CODE = "0";

    public ResponseResult(){
    }

    public Integer code() {
        return getCode();
    }

    public String msg() {
        return getMsg();
    }

    public T data() {
        return getData();
    }

    /**
     * data != null
     * @return true/false
     */
    public boolean hasData() {
        return Objects.nonNull(data());
    }

    /**
     * "0".equals(code)
     * @return true/false
     */
    public boolean successful() {
        return SUCCESS_CODE.equals(code());
    }

    public boolean failure() {
        return !successful();
    }

    /**
     * "OK".equalsIgnoreCase(code)
     * @return true/false
     */
    public boolean ok() {
        return HttpStatus.OK.value()==(code());
    }

}
